package nl.haemers.utils 
{
	import flash.errors.IllegalOperationError;
	import flash.utils.getQualifiedClassName;
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class Logger
	{		
		protected static var _debugMode			:Boolean = true;
		
		private static var _logger				:Logger;
		
		public function Logger() 
		{
			if (_logger)
			{
				throw new IllegalOperationError("Logger is an Singleton class and should not be initiated");
			}
		}
		
		public static function getInstance() : Logger
		{
			if (!_logger)
			{
				_logger = new Logger();
			}
			return _logger;
		}
		/**
		 * Info message
		 * @param	msg <code>String<code> message.
		 * @param	instance the <code>Class</code> who is calling the logger
		 */
		public static function i(msg:*, instance:Object = null) : void
		{
			if (_debugMode)
			{
				var message:String = "";
				if (instance)
				{
					message = "Info from: " + getQualifiedClassName(instance) + " - ";
				}
				message += "Message: " + String(msg) + "\n";
				
				output(message);
			}
		}
		
		public static function w(msg:*, instance:Object = null) : void
		{
			if (_debugMode)
			{
				var message:String = "";
				if (instance)
				{
					message = "Warning from: " + getQualifiedClassName(instance) + " - ";
				}
				message += "Message: " + String(msg) + "\n";
				
				output(message);
			}
		}
		
		public function get debugMode() : Boolean
		{ 
			return _debugMode;
		}
		public function set debugMode( value:Boolean ) : void 
		{
			_debugMode = value;
		}
		
		/** Protected methods **/
		protected static function output(msg:String) : void
		{
			trace(msg);
		}
		
	}

}